import { isEnabled } from '@automattic/calypso-config';
import { __, _x } from '@wordpress/i18n';
import { useSelector } from 'calypso/state';
import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import type { Category } from '.';

export const ALLOWED_CATEGORIES = [
	'analytics',
	'booking',
	'customer',
	'design',
	'discover',
	'donations',
	'ecommerce',
	'education',
	'email',
	'events',
	'finance',
	'marketing',
	'photo',
	'posts',
	'security',
	'seo',
	'shipping',
	'social',
	'widgets',

	// "Top paid plugins", "Editors pick" etc aren't real categories but we
	// treat them like they are in the UI so include them here
	'popular',
	'featured',
	'paid',
	'monetization',
	'business',
	'onlinestore',

	// Additional categories to improve SEO
	'affiliate',
	'quiz',
	'landingpage',
	'forms',
	'reviews',
	'translation',
	'membership',
	'maps',
	'tables',
	'forums',
	'comments',
	'faq',
	'testimonials',
	'realestate',
	'survey',
	'accessibility',
	'projectmanagement',
	'jobBoards',
	'search',
	'portfolio',
	'rss',
	'knowledgebase',
	'storelocator',
	'newsfeed',
	'sliders',
	'schema',
	'music',
	'popups',
	'calculators',
	'advertising',
	'restaurantmenu',
	'recipes',
	// 'leadgeneration', // It does not return any results
	'contest',
	'accordion',
	'javascript',
	'community',
	'captcha',
	'wpbeginner',
];

export const getCategories: () => Record< string, Category > = () => ( {
	discover: {
		menu: __( 'Discover' ),
		title: __( 'Discover' ),
		slug: 'discover',
		tags: [],
		preview: [],
	},
	paid: {
		menu: __( 'Premium plugins' ),
		title: isEnabled( 'marketplace-redesign' )
			? __( 'Must-have plugins' )
			: __( 'Must-have premium plugins' ),
		description: isEnabled( 'marketplace-redesign' )
			? __( 'Add the most popular plugins on WordPress.com.' )
			: __( 'Take your site further with these premium plugins.' ),
		slug: 'paid',
		tags: [],
		preview: [],
	},
	popular: {
		menu: __( 'Popular plugins' ),
		title: isEnabled( 'marketplace-redesign' )
			? __( 'The free essentials' )
			: __( 'Popular plugins' ),
		description: __( 'Add and install the most popular free plugins.' ),
		slug: 'popular',
		tags: [],
		preview: [],
	},
	featured: {
		menu: __( 'Developer favorites' ),
		title: isEnabled( 'marketplace-redesign' )
			? __( 'Our favorites' )
			: __( 'Our developers’ favorites' ),
		description: isEnabled( 'marketplace-redesign' )
			? __( "Start faster with the WordPress.com team's picks." )
			: __( 'Start fast with these WordPress.com team picks.' ),
		slug: 'featured',
		tags: [],
		preview: [],
	},
	seo: {
		menu: __( 'Search engine optimization' ),
		title: __( 'Search engine optimization' ),
		description: __( 'Fine-tune your site’s content and metadata for search engine success.' ),
		icon: 'grid',
		slug: 'seo',
		tags: [ 'seo' ],
		preview: [],
	},
	ecommerce: {
		menu: __( 'Ecommerce & business' ),
		title: __( 'Powering your online store' ),
		icon: 'grid',
		slug: 'ecommerce',
		tags: [ 'ecommerce', 'e-commerce', 'woocommerce', 'payments' ],
		description: __( 'Tools that will set you up to optimize your online business.' ),
		preview: [
			{
				slug: 'woocommerce-subscriptions',
				name: __( 'WooCommerce Subscriptions' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2012/09/Woo_Subscriptions_icon-marketplace-160x160-2.png',
				short_description: __( 'Let customers subscribe to your service' ),
			},
			{
				slug: 'woocommerce-xero',
				name: __( 'Xero' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2012/08/xero2.png',
				short_description: __( 'Sync your site with your Xero account' ),
			},
			{
				slug: 'automatewoo',
				name: __( 'AutomateWoo' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2019/10/woo-AutomateWoo.png',
				short_description: __( 'Create a range of automated workflows' ),
			},
			{
				slug: 'woocommerce-shipment-tracking',
				name: __( 'Shipment tracking' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2012/05/Shipment_Tracking_icon-marketplace-160x160-2.png',
				short_description: __( 'Provide shipment tracking information' ),
			},
			{
				slug: 'woocommerce-shipping-usps',
				name: __( 'WooCommerce USPS Shipping' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2013/01/woo-USPS-yhn1rb.png',
				short_description: __( 'Get shipping rates from the USPS API' ),
			},
			{
				slug: 'woocommerce-paypal-payments',
				name: __( 'WooCommerce PayPal Payments' ),
				icon: 'https://ps.w.org/woocommerce-paypal-payments/assets/icon-256x256.png?rev=3234615',
				short_description: __( 'Accept PayPal payments' ),
			},
			{
				slug: 'woocommerce',
				name: __( 'WooCommerce' ),
				icon: 'https://ps.w.org/woocommerce/assets/icon-256x256.png?rev=3234504',
				short_description: __(
					'Everything you need to launch an online store in days and keep it growing for years. From your first sale to millions in revenue, Woo is with you.'
				),
			},
			{
				slug: 'woocommerce-analytics',
				name: __( 'WooCommerce Analytics' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2024/12/Storefront_Parallax_Hero_icon-order-attribution-160x160-1.png',
				short_description: __(
					"WooCommerce Analytics has advanced order attribution reporting that provides powerful insights into each order's last-touch data, whether you're just launching or have thousands of products in your catalog."
				),
			},
			{
				slug: 'woocommerce-bookings',
				name: __( 'WooCommerce Bookings' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2014/05/Bookings_icon-marketplace-160x160-2.png',
				short_description: __(
					'Allow customers to book appointments, make reservations or rent equipment without leaving your site.'
				),
			},
			{
				slug: 'woocommerce-payments',
				name: __( 'WooPayments: Integrated WooCommerce Payments' ),
				icon: 'https://ps.w.org/woocommerce-payments/assets/icon-256x256.png?rev=3234740',
				short_description: __(
					'Securely accept credit and debit cards on your WooCommerce store. Manage payments without leaving your WordPress dashboard. Only with WooPayments.'
				),
			},
			{
				slug: 'woocommerce-gateway-stripe',
				name: __( 'WooCommerce Stripe Payment Gateway' ),
				icon: 'https://ps.w.org/woocommerce-gateway-stripe/assets/icon-256x256.png?rev=3177277',
				short_description: __(
					'Accept debit and credit cards in 135+ currencies, many local methods like Alipay, ACH, and SEPA, and express checkout with Apple Pay and Google Pay.'
				),
			},
			{
				slug: 'woocommerce-services',
				name: __( 'WooCommerce Tax (formerly WooCommerce Shipping & Tax)' ),
				icon: 'https://ps.w.org/woocommerce-services/assets/icon-256x256.png?rev=3234419',
				short_description: __(
					"We're here to help with tax rates: collect accurate sales tax, automatically."
				),
			},
			{
				slug: 'woocommerce-one-page-checkout',
				name: __( 'WooCommerce One Page Checkout' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2014/10/One_Page_Checkout_icon-marketplace-80x80-1.png',
				short_description: __(
					'Create special pages where customers can choose products, checkout & pay all on the one page.'
				),
			},
			{
				slug: 'woocommerce-product-filters',
				name: __( 'Product Filters for WooCommerce' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2018/10/Product_Filters_icon-marketplace-80x80-1.png',
				short_description: __(
					'This is a tool to create ajax product filters that make the process of finding products in your store simple and fast'
				),
			},
			{
				slug: 'woocommerce-additional-variation-images',
				name: __( 'WooCommerce Additional Variation Images' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2014/08/Additional_Variation_Images_icon-marketplace-160x160-2.png',
				short_description: __( 'Unlimited images for your product variations.' ),
			},
			{
				slug: 'woocommerce-shipping-per-product',
				name: __( 'Per Product Shipping' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2013/04/Per_product_shipping_icon-marketplace-160x160-1.png',
				short_description: __(
					'Define separate shipping costs per product which are combined at checkout to provide a total shipping cost.'
				),
			},
			{
				slug: 'automatewoo-referrals',
				name: __( 'AutomateWoo - Refer A Friend add-on' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2019/10/woo-AutomateWoo-m4jpva.png ',
				short_description: __(
					'Boost your organic sales by adding a customer referral program to your WooCommerce store.'
				),
			},
			{
				slug: 'warranty-requests',
				name: __( 'Returns and Warranty Requests' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2013/07/Returns_and_Warranty_Woo.png',
				short_description: __(
					'Manage the RMA process, add warranties to products, and let customers request and manage returns/exchanges from their account.'
				),
			},
		],
	},
	booking: {
		menu: __( 'Booking & scheduling' ),
		title: __( 'Booking & scheduling' ),
		description: __( 'Take bookings and manage your availability right from your site.' ),
		icon: 'grid',
		slug: 'booking',
		tags: [ 'booking', 'scheduling', 'appointment', 'reservation', 'booking-calendar' ],
		preview: [],
	},
	events: {
		menu: __( 'Events calendar' ),
		title: __( 'Events calendar' ),
		description: __( 'Build buzz and set the scene with an on-site events calendar.' ),
		icon: 'grid',
		slug: 'events',
		tags: [ 'events-calendar', 'calendar', 'calendar-event' ],
		preview: [],
	},
	social: {
		menu: _x( 'Social', 'category name' ),
		title: __( 'Social' ),
		description: __( 'Connect to your audience and amplify your content on social.' ),
		icon: 'grid',
		slug: 'social',
		tags: [ 'social', 'facebook', 'twitter', 'instagram', 'tiktok', 'youtube', 'pinterest' ],
		preview: [],
	},
	email: {
		menu: __( 'Email' ),
		title: __( 'Email' ),
		description: __( 'Forge a direct connection with your readers through email.' ),
		icon: 'grid',
		slug: 'email',
		tags: [ 'email' ],
		preview: [],
	},
	security: {
		menu: __( 'Security' ),
		title: __( 'Security' ),
		description: __( 'Take advanced control of your site’s security.' ),
		icon: 'grid',
		slug: 'security',
		tags: [ 'security' ],
		preview: [],
	},
	finance: {
		menu: __( 'Finance & payments' ),
		title: __( 'Finance & payments' ),
		description: __(
			'Sell products, subscriptions, and services while keeping on top of every transaction.'
		),
		icon: 'grid',
		slug: 'finance',
		tags: [ 'finance', 'payment', 'credit-card', 'payment-gateway' ],
		preview: [],
	},
	shipping: {
		menu: __( 'Shipping & delivery' ),
		title: __( 'Shipping & delivery' ),
		description: __( 'Create a seamless shipping experience with advanced delivery integrations.' ),
		icon: 'grid',
		slug: 'shipping',
		tags: [
			'shipping',
			'usps',
			'woocommerce-shipping',
			'delivery',
			'shipment-tracking',
			'food-delivery',
			'food-pickup',
			'courier',
		],
		preview: [],
	},
	analytics: {
		menu: __( 'Analytics' ),
		title: __( 'Analytics' ),
		description: __( 'Go deeper and learn faster with site visitor and performance insights.' ),
		icon: 'grid',
		slug: 'analytics',
		tags: [ 'analytics', 'google analytics', 'ga', 'stats', 'statistics' ],
		preview: [],
	},
	marketing: {
		menu: __( 'Marketing' ),
		title: __( 'Marketing' ),
		description: __( 'Bring in new business and shine a spotlight on your projects or products.' ),
		icon: 'grid',
		slug: 'marketing',
		tags: [ 'marketing' ],
		preview: [],
	},
	design: {
		menu: __( 'Design' ),
		title: __( 'Design' ),
		description: __( 'Finesse your site’s design with advanced customization tools.' ),
		icon: 'grid',
		slug: 'design',
		tags: [ 'design', 'blocks', 'editor' ],
		preview: [],
	},
	photo: {
		menu: __( 'Photo & video' ),
		title: __( 'Photo & video' ),
		description: __(
			'Create, share, edit, and manage beautiful images and video {with added precision and flexibility.'
		),
		icon: 'grid',
		slug: 'photo',
		tags: [ 'photo', 'video', 'media' ],
		preview: [],
	},
	customer: {
		menu: __( 'CRM & live chat' ),
		title: __( 'CRM & live chat' ),
		description: __( 'Create stand-out customer service experiences for your site visitors.' ),
		icon: 'grid',
		slug: 'customer',
		tags: [ 'customer-service', 'live-chat', 'crm' ],
		preview: [],
	},
	donations: {
		menu: __( 'Crowdfunding' ),
		title: __( 'Crowdfunding' ),
		description: __( 'Launch and run crowdfunding campaigns right from your site.' ),
		icon: 'grid',
		slug: 'donations',
		tags: [
			'donation',
			'donation-plugin',
			'donations',
			'donate',
			'fundraising',
			'crowdfunding',
			'recurring-donations',
			'charity',
		],
		preview: [],
	},
	education: {
		menu: __( 'Learning management systems' ),
		title: __( 'Learning management systems' ),
		description: __( 'Create, run, and manage interactive courses and learning experiences.' ),
		icon: 'grid',
		slug: 'education',
		tags: [ 'education', 'lms', 'learning-management-systems', 'elearning' ],
		preview: [],
	},
	widgets: {
		menu: __( 'Widgets' ),
		title: __( 'Widgets' ),
		description: __( 'Take widgets to the next level with advanced control and customization.' ),
		icon: 'grid',
		slug: 'widgets',
		tags: [ 'widgets' ],
		preview: [],
	},
	posts: {
		menu: __( 'Posts & posting' ),
		title: __( 'Posts & posting' ),
		description: __( 'Unlock advanced content planning, publishing, and scheduling features.' ),
		icon: 'grid',
		slug: 'posts',
		tags: [ 'posts', 'post', 'page', 'pages' ],
		preview: [],
	},
	monetization: {
		menu: __( 'Monetization' ),
		title: isEnabled( 'marketplace-redesign' )
			? __( 'Do more, sell more, earn more' )
			: __( 'Supercharging and monetizing your blog' ),
		slug: 'monetization',
		description: isEnabled( 'marketplace-redesign' )
			? __( 'Making money with your site is easier than you`d think.' )
			: __( 'Building a money-making blog doesn’t have to be as hard as you might think.' ),
		tags: [ 'affiliate-marketing', 'advertising', 'adwords' ],
		preview: [
			{
				slug: 'wordpress-seo-premium',
				name: __( 'Yoast SEO Premium' ),
				icon: 'https://ps.w.org/wordpress-seo/assets/icon-256x256.gif',
				short_description: __( 'Optimize your site for search engines' ),
			},
			{
				slug: 'give',
				name: __( 'GiveWP' ),
				icon: 'https://ps.w.org/give/assets/icon-256x256.jpg?rev=2659032',
				short_description: __( 'Create donation pages and collect more' ),
			},
			{
				slug: 'sensei-pro',
				name: __( 'Sensei Pro' ),
				icon: 'https://wordpress.com/wp-content/lib/marketplace-images/sensei-pro.svg',
				short_description: __( 'Manage and sell digital courses' ),
			},
			{
				slug: 'optinmonster',
				name: __( 'OptinMonster' ),
				icon: 'https://ps.w.org/optinmonster/assets/icon-256x256.png',
				short_description: __( 'Monetize your website traffic' ),
			},
			{
				slug: 'easy-digital-downloads',
				name: __( 'Easy Digital Downloads' ),
				icon: 'https://ps.w.org/easy-digital-downloads/assets/icon.svg',
				short_description: __( 'Create and sell digital products' ),
			},
			{
				slug: 'elementor',
				name: __( 'Elementor' ),
				icon: 'https://ps.w.org/elementor/assets/icon-256x256.gif?rev=3111597',
				short_description: __( 'Drag and drop page builder' ),
			},
			{
				slug: 'ads-txt',
				name: __( 'Ads.txt Manager' ),
				icon: 'https://ps.w.org/ads-txt/assets/icon-256x256.png?rev=2834081',
				short_description: __(
					'Create, manage, and validate your ads.txt and app-ads.txt from within WordPress, like any other content asset.'
				),
			},
			{
				slug: 'advanced-popups',
				name: __( 'Advanced Popups' ),
				icon: 'https://ps.w.org/advanced-popups/assets/icon-256x256.png?rev=2690535',
				short_description: __(
					'Display high-converting newsletter popups, a cookie notice, or a notification with the light-weight yet feature-rich plugin.'
				),
			},
			{
				slug: 'kliken-marketing-for-google',
				name: __( 'AI Powered Marketing' ),
				icon: 'https://ps.w.org/kliken-marketing-for-google/assets/icon-256x256.png?rev=2832456',
				short_description: __(
					"Kliken's all-in-one marketing helps businesses reach high-intent customers, beat the competition and see sales growth while lowering conversion costs"
				),
			},
			{
				slug: 'website-monetization-by-magenet',
				name: __( 'Website Monetization by MageNet' ),
				icon: 'https://ps.w.org/website-monetization-by-magenet/assets/icon-256x256.jpg?rev=1630832',
				short_description: __(
					'Get additional income from your website or blog by placing text ads automatically.'
				),
			},
			{
				slug: 'website-article-monetization-by-magenet',
				name: __( 'Website Article Monetization By MageNet' ),
				icon: 'https://ps.w.org/website-article-monetization-by-magenet/assets/icon-256x256.jpg?rev=2300741',
				short_description: __(
					'Get additional income from your website or blog by placing text ads automatically.'
				),
			},
			{
				slug: 'affiliatex',
				name: __( 'AffiliateX – Affiliate Block Plugin' ),
				icon: 'https://ps.w.org/affiliatex/assets/icon-256x256.jpg?rev=2636351',
				short_description: __(
					'AffiliateX is the best WordPress Affiliate Block Plugin. Create professional affiliate websites with customizable WordPress Affiliate Blocks.'
				),
			},
			{
				slug: 'mediavine-control-panel',
				name: __( 'Mediavine Control Panel' ),
				icon: 'https://ps.w.org/mediavine-control-panel/assets/icon-128x128.png?rev=1605431',
				short_description: __( 'Manage your ads, analytics and more with our lightweight plugin!' ),
			},
			{
				slug: 'content-egg',
				name: __( 'Content Egg – Affiliate Product Importer & Price Comparison' ),
				icon: 'https://ps.w.org/content-egg/assets/icon-128x128.png?rev=1236433',
				short_description: __(
					'Import affiliate products, compare prices, sync to WooCommerce, and auto-generate SEO content with AI — all in one toolkit.'
				),
			},
			{
				slug: 'affiliates-manager',
				name: __( 'Affiliates Manager' ),
				icon: 'https://ps.w.org/affiliates-manager/assets/icon-128x128.png?rev=981249',
				short_description: __(
					'Affiliates Manager plugin can help you manage an affiliate marketing program to drive more traffic and more sales to your site.'
				),
			},
			{
				slug: 'meks-easy-ads-widget',
				name: __( 'Meks Easy Ads Widget' ),
				icon: 'https://ps.w.org/meks-easy-ads-widget/assets/icon-256x256.png?rev=1522332',
				short_description: __( 'Display unlimited number of ads inside your WordPress widget.' ),
			},
			{
				slug: 'callrail-phone-call-tracking',
				name: __( 'CallRail Phone Call Tracking' ),
				icon: 'https://ps.w.org/callrail-phone-call-tracking/assets/icon-256x256.png?rev=2227520',
				short_description: __(
					"Dynamically swap CallRail tracking phone numbers based on the visitor's referring source."
				),
			},
			{
				slug: 'yith-woocommerce-affiliates',
				name: __( 'YITH WooCommerce Affiliates' ),
				icon: 'https://ps.w.org/yith-woocommerce-affiliates/assets/icon-256x256.jpg?rev=3089234',
				short_description: __(
					'YITH WooCommerce Affiliates allows you to create affiliate profiles and grant your affiliates earnings each time someone purchases from their link.'
				),
			},
		],
	},
	business: {
		menu: _x( 'Business', 'category name' ),
		title: isEnabled( 'marketplace-redesign' )
			? __( 'Set up your business' )
			: __( 'Setting up your local business' ),
		slug: 'business',
		description: isEnabled( 'marketplace-redesign' )
			? __( 'Find the perfect plugin to build and grow.' )
			: __( 'These plugins are here to keep your business on track.' ),
		tags: [ 'google', 'testimonials', 'crm', 'business-directory' ],
		preview: [
			{
				slug: 'wordpress-seo-premium',
				name: __( 'Yoast SEO Premium' ),
				icon: 'https://ps.w.org/wordpress-seo/assets/icon-256x256.gif',
				short_description: __( 'Optimize your site for search engines' ),
			},
			{
				slug: 'woocommerce-bookings',
				name: __( 'WooCommerce Bookings' ),
				icon: 'https://woocommerce.com/wp-content/uploads/2014/05/Bookings_icon-marketplace-160x160-1.png',
				short_description: __( 'Allow customers to book appointments' ),
			},
			{
				slug: 'mailpoet',
				name: __( 'MailPoet' ),
				icon: 'https://ps.w.org/mailpoet/assets/icon-256x256.png?rev=2784430',
				short_description: __( 'Send emails and create loyal customers' ),
			},
			{
				slug: 'zero-bs-crm',
				name: __( 'Jetpack CRM' ),
				icon: 'https://ps.w.org/zero-bs-crm/assets/icon.svg',
				short_description: __( 'Lead generation and marketing automation' ),
			},
			{
				slug: 'strong-testimonials',
				name: __( 'Strong Testimonials' ),
				icon: 'https://ps.w.org/strong-testimonials/assets/icon-256x256.png',
				short_description: __( 'Easily collect and display testimonials' ),
			},
			{
				slug: 'all-in-one-wp-migration',
				name: __( 'All-in-One WP Migration' ),
				icon: 'https://ps.w.org/all-in-one-wp-migration/assets/icon-256x256.png',
				short_description: __( 'Move websites between hosts with ease' ),
			},
			{
				slug: 'google-site-kit',
				name: __( 'Site Kit by Google - Analytics, Search Console, AdSense, Speed' ),
				icon: 'https://ps.w.org/google-site-kit/assets/icon-256x256.png?rev=3141863',
				short_description: __(
					'Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.'
				),
			},
			{
				slug: 'google-listings-and-ads',
				name: __( 'Google for WooCommerce' ),
				icon: 'https://ps.w.org/google-listings-and-ads/assets/icon-256x256.png?rev=2775988',
				short_description: __(
					"Native integration with Google that allows merchants to easily display their products across Google's network."
				),
			},
			{
				slug: 'wp-reviews-plugin-for-google',
				name: __( 'Widgets for Google Reviews' ),
				icon: 'https://ps.w.org/wp-reviews-plugin-for-google/assets/icon-256x256.png?rev=2721569',
				short_description: __(
					'Embed Google reviews fast and easily into your WordPress site. Increase SEO, trust and sales using Google reviews.'
				),
			},
			{
				slug: 'flamingo',
				name: __( 'Flamingo' ),
				icon: 'https://ps.w.org/flamingo/assets/icon-128x128.png?rev=1540977',
				short_description: __( 'A trustworthy message storage plugin for Contact Form 7.' ),
			},
			{
				slug: 'ga-google-analytics',
				name: __( 'GA Google Analytics – Connect Google Analytics to WordPress' ),
				icon: 'https://ps.w.org/ga-google-analytics/assets/icon-256x256.png?rev=2053004',
				short_description: __(
					'Adds Google Analytics 4 tracking code to your WordPress site. Supports many tracking features.'
				),
			},
			{
				slug: 'leadin',
				name: __( 'HubSpot - CRM, Email Marketing, Live Chat, Forms & Analytics' ),
				icon: 'https://ps.w.org/leadin/assets/icon-256x256.png?rev=3041936',
				short_description: __(
					'The CRM, Sales, and Marketing WordPress plugin to grow your business better. Capture, organize, and engage web visitors with free live chat, forms, CR …'
				),
			},
			{
				slug: 'reviews-feed',
				name: __(
					'Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More'
				),
				icon: 'https://ps.w.org/reviews-feed/assets/icon-256x256.png?rev=2885733',
				short_description: __(
					'No API key required. Display Yelp and Google reviews for any business in a clean, customizable feed on your site.'
				),
			},
			{
				slug: 'event-tickets',
				name: __( 'Event Tickets and Registration' ),
				icon: 'https://ps.w.org/event-tickets/assets/icon-256x256.png?rev=2259359',
				short_description: __(
					'Event Tickets allows your visitors to RSVP and buy tickets to events on your site. Also works seamlessly with The Events Calendar.'
				),
			},
			{
				slug: 'wp-job-manager',
				name: __( 'WP Job Manager' ),
				icon: 'https://ps.w.org/wp-job-manager/assets/icon-256x256.gif?rev=2975257',
				short_description: __(
					'Create a careers page for your company website, or build a public job board for your community.'
				),
			},
			{
				slug: 'auto-terms-of-service-and-privacy-policy',
				name: __(
					'TermsFeed AutoTerms: Privacy Policy Generator, Cookie Consent, GDPR, CCPA, Terms & Conditions, Disclaimers, Cookies Policy, EULA'
				),
				icon: 'https://ps.w.org/auto-terms-of-service-and-privacy-policy/assets/icon-256x256.png?rev=3300987',
				short_description: __(
					'All-in-One compliance solution from TermsFeed: Generator of Privacy Policy, T&Cs, Affiliate Disclaimers and Cookie Consent Notice Banner.'
				),
			},
			{
				slug: 'fluent-crm',
				name: __(
					'FluentCRM - Email Newsletter, Automation, Email Marketing, Email Campaigns, Optins, Leads, and CRM Solution'
				),
				icon: 'https://ps.w.org/fluent-crm/assets/icon-256x256.png?rev=2390407',
				short_description: __(
					'The easiest and fastest Email Marketing, Newsletter, Marketing Automation Plugin & CRM Solution for WordPress'
				),
			},
			{
				slug: 'site-reviews',
				name: __( 'Site Reviews' ),
				icon: 'https://ps.w.org/site-reviews/assets/icon-256x256.gif?rev=3307009',
				short_description: __(
					'Site Reviews is a complete review management solution for your website that is designed to work in a similar way to Amazon, Tripadvisor, and Yelp.'
				),
			},
		],
	},
	affiliate: {
		menu: __( 'Affiliate' ),
		title: __( 'Affiliate' ),
		slug: 'affiliate',
		tags: [ 'affiliate', 'affiliates', 'affiliate marketing' ],
		preview: [],
	},
	quiz: {
		menu: __( 'Quiz' ),
		title: __( 'Quiz' ),
		slug: 'quiz',
		tags: [ 'quiz', 'questionnaire', 'exam', 'personality quizzes' ],
		preview: [],
	},
	landingpage: {
		menu: __( 'Landing page' ),
		title: __( 'Landing page' ),
		slug: 'landingpage',
		tags: [ 'landing page', 'page builder', 'landing-page' ],
		preview: [],
	},
	forms: {
		menu: __( 'Forms' ),
		title: __( 'Forms' ),
		slug: 'forms',
		tags: [ 'form', 'forms' ],
		preview: [],
	},
	reviews: {
		menu: __( 'Reviews' ),
		title: __( 'Reviews' ),
		slug: 'reviews',
		tags: [ 'review', 'reviews', 'product reviews', 'customer reviews' ],
		preview: [],
	},
	translation: {
		menu: __( 'Translation' ),
		title: __( 'Translation' ),
		slug: 'translation',
		tags: [ 'translation', 'localization', 'bilingual', 'international' ],
		preview: [],
	},
	membership: {
		menu: __( 'Membership' ),
		title: __( 'Membership' ),
		slug: 'membership',
		tags: [ 'membership', 'members', 'members-only' ],
		preview: [],
	},
	maps: {
		menu: __( 'Maps' ),
		title: __( 'Maps' ),
		slug: 'maps',
		tags: [ 'map', 'maps', 'google map', 'google maps', 'directions' ],
		preview: [],
	},
	tables: {
		menu: __( 'Tables' ),
		title: __( 'Tables' ),
		slug: 'tables',
		tags: [ 'table', 'table builder' ],
		preview: [],
	},
	forums: {
		menu: __( 'Forums' ),
		title: __( 'Forums' ),
		slug: 'forums',
		tags: [ 'forum', 'forum plugin', 'community' ],
		preview: [],
	},
	comments: {
		menu: _x( 'Comment', 'category name' ),
		title: __( 'Comments & commenting' ),
		slug: 'comments',
		tags: [ 'comment', 'comments', 'comment fields', 'delete comments' ],
		preview: [],
	},
	faq: {
		menu: __( 'FAQ' ),
		title: __( 'FAQ' ),
		slug: 'faq',
		tags: [ 'faq', 'faqs', 'frequently asked questions' ],
		preview: [],
	},
	testimonials: {
		menu: __( 'Testimonials' ),
		title: __( 'Testimonials' ),
		slug: 'testimonials',
		tags: [ 'testimonials', 'testimonial', 'testimonial showcase' ],
		preview: [],
	},
	realestate: {
		menu: __( 'Real estate' ),
		title: __( 'Real estate' ),
		slug: 'realestate',
		tags: [
			'real estate',
			'agency',
			'property',
			'agent listings',
			'home asap',
			'MLS',
			'real-estate',
			'IDX',
		],
		preview: [],
	},
	survey: {
		menu: __( 'Survey' ),
		title: __( 'Survey' ),
		slug: 'survey',
		tags: [ 'survey', 'surveys', 'feedback', 'questionnaire' ],
		preview: [],
	},
	accessibility: {
		menu: __( 'Accessibility' ),
		title: __( 'Accessibility' ),
		slug: 'accessibility',
		tags: [ 'accessibility', 'accessible', 'navigation' ],
		preview: [],
	},
	projectmanagement: {
		menu: __( 'Project management' ),
		title: __( 'Project management' ),
		slug: 'projectmanagement',
		tags: [ 'gantt charts', 'kanban', 'project', 'project management', 'tasks', 'task management' ],
		preview: [],
	},
	jobboards: {
		menu: __( 'Job boards' ),
		title: __( 'Job boards' ),
		slug: 'jobboards',
		tags: [ 'career', 'job board', 'job listing' ],
		preview: [],
	},
	search: {
		menu: _x( 'Search', 'category name' ),
		title: __( 'Search' ),
		slug: 'search',
		tags: [ 'ajax search', 'image search', 'search and replace', 'search', 'google' ],
		preview: [],
	},
	portfolio: {
		menu: __( 'Portfolio' ),
		title: __( 'Portfolio' ),
		slug: 'portfolio',
		tags: [
			'portfolio',
			'add portfolio',
			'add portfolio widget',
			'portfolio gallery',
			'portfolio plugin',
		],
		preview: [],
	},
	rss: {
		menu: __( 'RSS' ),
		title: __( 'RSS' ),
		slug: 'rss',
		tags: [ 'feed', 'news', 'rss', 'rss feed' ],
		preview: [],
	},
	knowledgebase: {
		menu: __( 'Knowledge base' ),
		title: __( 'Knowledge base' ),
		slug: 'knowledgebase',
		tags: [ 'faq', 'faqs', 'frequently asked questions', 'knowledge base' ],
		preview: [],
	},
	storelocator: {
		menu: __( 'Store locator' ),
		title: __( 'Store locator' ),
		slug: 'storelocator',
		tags: [ 'business locations', 'geocoding', 'locators', 'dealer locator', 'directions' ],
		preview: [],
	},
	newsfeed: {
		menu: __( 'Newsfeed' ),
		title: __( 'Newsfeed' ),
		slug: 'newsfeed',
		tags: [ 'news', 'newsfeed', 'news feeds' ],
		preview: [],
	},
	sliders: {
		menu: __( 'Sliders' ),
		title: __( 'Sliders' ),
		slug: 'sliders',
		tags: [
			'image slider',
			'layer slider',
			'responsive slider',
			'photo slider',
			'slider',
			'gallery slider',
		],
		preview: [],
	},
	schema: {
		menu: __( 'Schema' ),
		title: __( 'Schema' ),
		slug: 'schema',
		tags: [
			'JSON-LD',
			'rich snippets',
			'schema',
			'schema.org',
			'schema markup',
			'google snippets',
			'structured data',
		],
		preview: [],
	},
	music: {
		menu: __( 'Music' ),
		title: __( 'Music' ),
		slug: 'music',
		tags: [
			'audio player',
			'audioplayer',
			'html5 audio player',
			'music',
			'music player',
			'bass',
			'guitar',
			'musician',
			'audio',
			'mp3',
		],
		preview: [],
	},
	popups: {
		menu: __( 'Popups' ),
		title: __( 'Popups' ),
		slug: 'popups',
		tags: [ 'optin', 'exit popup', 'pop up', 'popup builder', 'popup maker' ],
		preview: [],
	},
	calculators: {
		menu: __( 'Calculators' ),
		title: __( 'Calculators' ),
		slug: 'calculators',
		tags: [
			'calculator',
			'cost calculator',
			'calculator form builder',
			'cost estimator',
			'loan calculator',
			'mortgage calculator',
		],
		preview: [],
	},
	advertising: {
		menu: __( 'Advertising' ),
		title: __( 'Advertising' ),
		slug: 'advertising',
		tags: [ 'ads', 'google', 'ad codes', 'advertising', 'advert', 'advertise', 'advertisement' ],
		preview: [],
	},
	restaurantmenu: {
		menu: __( 'Restaurant menu' ),
		title: __( 'Restaurant menu' ),
		slug: 'restaurantmenu',
		tags: [
			'food ordering',
			'restaurant menu',
			'restaurant',
			'cafe menu',
			'food',
			'create menu',
			'restaurant main menu',
		],
		preview: [],
	},
	recipes: {
		menu: __( 'Recipes' ),
		title: __( 'Recipes' ),
		slug: 'recipes',
		tags: [
			'cooking',
			'food',
			'ingredients',
			'recipe',
			'chef',
			'print recipe',
			'recipe box',
			'recipe card',
			'food blog',
		],
		preview: [],
	},
	leadgeneration: {
		menu: __( 'Lead generation' ),
		title: __( 'Lead generation' ),
		slug: 'leadgeneration',
		tags: [ 'lead gen', 'lead generation' ],
		preview: [],
	},
	contest: {
		menu: __( 'Contest' ),
		title: __( 'Contest' ),
		slug: 'contest',
		tags: [ 'contest', 'photo contest', 'contests', 'giveaway' ],
		preview: [],
	},
	accordion: {
		menu: __( 'Accordion' ),
		title: __( 'Accordion' ),
		slug: 'accordion',
		tags: [ 'accordion', 'accordion faq', 'accordions' ],
		preview: [],
	},
	javascript: {
		menu: __( 'Javascript' ),
		title: __( 'Javascript' ),
		slug: 'javascript',
		tags: [ 'javascript', 'js' ],
		preview: [],
	},
	community: {
		menu: __( 'Community' ),
		title: __( 'Community' ),
		slug: 'community',
		tags: [ 'community', 'discussion', 'forum' ],
		preview: [],
	},
	captcha: {
		menu: __( 'Captcha' ),
		title: __( 'Captcha' ),
		slug: 'captcha',
		tags: [ 'captcha', 'invisible captcha', 'nocaptcha', 'CAPTCHA Code', 'anti-spam' ],
		preview: [],
	},
	wpbeginner: {
		menu: __( 'WPBeginner' ),
		title: __( 'Must-have plugins from WPBeginner' ),
		description: __( 'Add the best-loved plugins on WordPress.com.' ),
		slug: 'wpbeginner',
		tags: [ 'wpbeginner', 'Awesome Motive' ],
		preview: [],
		showOnlyActive: true,
	},
} );

/**
 * Get the first matching category from a collection of tags
 * @param {Array<string>} pluginTags - array of tags of a plugin
 * @returns string | undefined - category name or undefined if no category is found
 */
export function getFirstCategoryFromTags( pluginTags: Array< string > ) {
	const categories = getCategories();

	return Object.keys( categories ).find( ( category ) => {
		return pluginTags.some( ( pluginTag ) => categories[ category ].tags.includes( pluginTag ) );
	} );
}

export function useCategories(
	allowedCategories = ALLOWED_CATEGORIES
): Record< string, Category > {
	const siteId = useSelector( getSelectedSiteId ) as number;

	const isJetpack = useSelector(
		( state ) => isJetpackSite( state, siteId ) && ! isAtomicSite( state, siteId )
	);

	// Only showing these top level categories for now
	const allowed = allowedCategories.slice();

	// Jetpack sites shouldn't see paid plugins
	if ( isJetpack && allowed.indexOf( 'paid' ) >= 0 ) {
		allowed.splice( allowed.indexOf( 'paid' ), 1 );
	}

	return Object.fromEntries(
		Object.entries( getCategories() ).filter( ( [ key ] ) => allowed.includes( key ) )
	);
}
